#ifndef __TUMOBOT_TUMOBOT_TCC_REGEX_HPP__
#define __TUMOBOT_TUMOBOT_TCC_REGEX_HPP__
#include <string>
#include <boost/regex.hpp>

class tcc_smatch
{
public:
	tcc_smatch(char* txt)
		: txt_(txt), is_first_(true)
	{}
public:
	static tcc_smatch* tcc_smatch_new(char* txt)
	{
		return new tcc_smatch(txt);
	}
	static void tcc_smatch_delete(boost::smatch* match)
	{
		delete match;
	}
public:
	inline const char* tcc_get_match()
	{
		result_ = match_[0];
		return result_.c_str();
	}
	inline std::string::const_iterator& begin()
	{
		if (is_first_)
		{
			begin_ = txt_.begin();
			is_first_ = false;
		}
		else
		{
			begin_ = match_[0].second;
		}

		return begin_;
	}
	inline std::string::const_iterator& end()
	{
		if (is_first_)
			end_ = txt_.end();
		
		return end_;
	}
	inline boost::smatch& get_smatch()
	{
		return match_;
	}
private:
	boost::smatch match_;
	std::string txt_;
	std::string result_;
	bool is_first_;
	std::string::const_iterator begin_;
	std::string::const_iterator end_;
};
class tcc_regex
{
public:
	tcc_regex(char* txt)
		: reg_(txt, boost::regex::icase)
	{}
public:
	bool tcc_regex_search(tcc_smatch* match)
	{
		return boost::regex_search(match->begin(), match->end(), match->get_smatch(), reg_);
	}
public:
	static tcc_regex* tcc_regex_new(char* txt)
	{
		return new tcc_regex(txt);
	}
	static void tcc_regex_delete(tcc_regex* reg)
	{
		delete reg;
	}
private:
	boost::regex reg_;
};


#endif//__TUMOBOT_TUMOBOT_TCC_REGEX_HPP__